﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BookClubIt.Account
{
    public partial class inbox : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           DTO.Club_Messages messages = MemberProcessorInstance.GetMemberMessages(CurrentUserId);
           grdMessages.DataSource = messages;
           grdMessages.DataBind();

        }

        public void BindData(DTO.Club_Messages messages)
        {
            grdMessages.DataSource = messages;
            grdMessages.DataBind();
        }

        protected void grdMessages_OnRowDataBound(object sender, GridViewRowEventArgs e)
        {
            DTO.Club_Message message = e.Row.DataItem as DTO.Club_Message;

            if (e.Row.RowType != DataControlRowType.DataRow)
                return;

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
               // HyperLink lnkMember = ((HyperLink)e.Row.FindControl("lnkMember"));
              //  Image imgMemberAvatar = ((Image)e.Row.FindControl("imgMemberAvatar"));
                Label lblSentDate = ((Label)e.Row.FindControl("lblSentDate"));
                HyperLink lnkFromUsername = ((HyperLink)e.Row.FindControl("lnkFromUsername"));
                Label lblMessageText = ((Label)e.Row.FindControl("lblMessageText"));

                DTO.Member sentFrom = MemberProcessorInstance.GetMemberById(message.Sender_User_Id);

                lblSentDate.Text = message.Sent_Date.ToString();
                lnkFromUsername.Text = sentFrom.Username;
                lnkFromUsername.NavigateUrl = "../member.aspx?uid=" + sentFrom.Id;
                lblMessageText.Text = message.Message_Text;
            }
        }
    }
}